package com.enjoyor.soa.traffic.core.efoms.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.enjoyor.soa.traffic.core.efoms.domain.DeviceDetailInfo;
import com.enjoyor.soa.traffic.core.efoms.enums.EnumDicPublic;
import com.enjoyor.soa.traffic.core.efoms.mapper.IDeviceDetailInfoMapper;
import com.enjoyor.soa.traffic.core.efoms.service.IDeviceDetailInfoService;
import com.enjoyor.soa.traffic.util.helper.LoggerHelper;
import com.enjoyor.soa.traffic.util.pojo.Page;

@Service
@Transactional
public class DeviceDetailInfoService implements IDeviceDetailInfoService {

    @Autowired
    private IDeviceDetailInfoMapper deviceDetailInfoMapper;

    /***
     * 获取资产（设备）对象信息
     * @param devTypeCode 设备类型编号
     * @param devId 设备编号
     */
    @Override
    public DeviceDetailInfo selectDeviceDetailInfoById(String devTypeCode, String devId){
    	try {
    		DeviceDetailInfo deviceDetailInfo = null;
    		List<DeviceDetailInfo> deviceDetailInfoList = this.selectDeviceDetailInfoList(devTypeCode, devId, 
    				null, null, null, null, null);
	    	if(null != deviceDetailInfoList && deviceDetailInfoList.size() > 0) {
	    		deviceDetailInfo = deviceDetailInfoList.get(0);
	    	}
	    	return deviceDetailInfo;
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }
    
    /***
     * 获取资产（设备）对象信息
     * @param devTypeCode 设备类型编号
     * @param devId 设备编号
     * @param key 查询标识
     * @param devAreaCode 区域编号
     * @param devDeptId 部门编号
     * @param ledType 诱导屏类型编号
     */
    @Override
	public List<DeviceDetailInfo> selectDeviceDetailInfoList(String devTypeCode, String devId, String devName,
			String key, String devAreaCode, String devDeptId, String ledType){
    	try {
	    	Map<String,Object> paramT = new HashMap<String ,Object>();
	    	paramT.put("devTypeCode", devTypeCode);
	    	paramT.put("devId", devId);
	    	paramT.put("devName", devName);
	    	paramT.put("key", key);
	    	paramT.put("devAreaCode", devAreaCode);
	    	paramT.put("devDeptId", devDeptId);
	    	paramT.put("ledType", ledType);
	    	return deviceDetailInfoMapper.selectDeviceDetailInfoList(paramT);
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }
    
    @Override
    @SuppressWarnings({ "rawtypes", "unchecked" })
	public Page selectDeviceDetailInfoPage(String devTypeCode, String devId, String devName,
			String key, String devAreaCode, String devDeptId, String ledType, String deviceStatus,Page page){
    	try {
	    	Map<String,Object> mapBean = new HashMap<String ,Object>();
	    	mapBean.put("devTypeCode", devTypeCode);
	    	mapBean.put("devId", devId);
	    	mapBean.put("devName", devName);
	    	mapBean.put("key", key);
	    	mapBean.put("devAreaCode", devAreaCode);
	    	mapBean.put("devDeptId", devDeptId);
	    	mapBean.put("ledType", ledType);
	    	mapBean.put("deviceStatus", deviceStatus);
	    	page.setMapBean(mapBean);
	    	return deviceDetailInfoMapper.selectPageInfo(page);
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }
    
    @Override
    @SuppressWarnings({ "rawtypes", "unchecked" })
	public Page selectVideoByPage(String videoGroupId, String isSelect, String devId, String devName,
			String key, String devAreaCode, String devDeptId,String deviceStatus, Page page){
    	try {
	    	Map<String,Object> mapBean = new HashMap<String ,Object>();
	    	mapBean.put("videoGroupId", videoGroupId);
	    	mapBean.put("isSelect", isSelect);
	    	mapBean.put("devTypeCode", EnumDicPublic.VIDEO.getKey());
	    	mapBean.put("devId", devId);
	    	mapBean.put("devName", devName);
	    	mapBean.put("key", key);
	    	mapBean.put("devAreaCode", devAreaCode);
	    	mapBean.put("devDeptId", devDeptId);
	    	mapBean.put("deviceStatus", deviceStatus);
	    	page.setMapBean(mapBean);
	    	return deviceDetailInfoMapper.selectVideoByPage(page);
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }
    
    @Override
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public Page selectAssetDevicePage(String devTypeCode, String DevId, String devName, String key,
			String devStatusCode, String devAreaCode, String devDeptId, String devFactory, String oppmDept,
			String repStatusCode, String buildBeginDate, String buildEndDate, String shelfBeginDate,
			String shelfEndDate, String oppmBeginDate, String oppmEndDate,String deviceStatus, Page page) {
    	try {
	    	Map<String,Object> mapBean = new HashMap<String ,Object>();
	    	mapBean.put("devTypeCode", devTypeCode);
	    	mapBean.put("DevId", DevId);
	    	mapBean.put("devName", devName);
	    	mapBean.put("key", key);
	    	mapBean.put("devStatusCode", devStatusCode);
	    	mapBean.put("devAreaCode", devAreaCode);
	    	mapBean.put("devFactory", devFactory);
	    	mapBean.put("repStatusCode", repStatusCode);
	    	mapBean.put("buildBeginDate", buildBeginDate);
	    	mapBean.put("buildEndDate", buildEndDate);
	    	mapBean.put("shelfBeginDate", shelfBeginDate);
	    	mapBean.put("shelfEndDate", shelfEndDate);
	    	mapBean.put("oppmBeginDate", oppmBeginDate);
	    	mapBean.put("oppmEndDate", oppmEndDate);
	    	mapBean.put("deviceStatus", deviceStatus);
	    	mapBean.put("oppmDept", oppmDept);
	    	page.setMapBean(mapBean);
	    	return deviceDetailInfoMapper.selectAssetDevicePage(page);
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }
}
